package team.scau.laboratory_repair.service;

import com.querydsl.core.types.dsl.EntityPathBase;
import com.querydsl.jpa.impl.JPAQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.scau.laboratory_repair.common.base.BaseService;
import team.scau.laboratory_repair.modules.po.Note;
import team.scau.laboratory_repair.modules.po.QNote;
import team.scau.laboratory_repair.modules.repository.NoteRepository;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 30254
 * creadtedate: 2018/10/25
 */
@Service
public class NoteService extends BaseService<Note, NoteRepository> {
    @Autowired
    private NoteRepository repository;

    private QNote qNote = QNote.note;

    @Override
    public NoteRepository getRepository() {
        return repository;
    }

    @Override
    public EntityPathBase<Note> getQBase() {
        return qNote;
    }

    public List<Note> listByIds(List<Long> ids) {
        if(ids == null || ids.size() == 0){
            return new ArrayList<>();
        }
        JPAQuery<Note> jpaQuery = queryFactory.select(qNote).from(qNote)
                .where(qNote.recordId.in(ids)).where(qNote.valid.eq(true));
        return jpaQuery.fetch();
    }
}
